// player.ts
import { AnimalCard, FlipCard } from './interfaces';
import { Fruit } from './enums';

export class Player {
  id: number;
  animalCards: AnimalCard[];
  currentAnimalIndex: number = 0;
  collectedFruits: Set<Fruit> = new Set();
  isActive: boolean = false;

  constructor(id: number, animalCards: AnimalCard[]) {
    this.id = id;
    this.animalCards = animalCards;
  }

  getCurrentTargetFruits(): number[] {
    if (this.currentAnimalIndex >= this.animalCards.length) return [];
    return this.animalCards[this.currentAnimalIndex].fruits;
  }

  isCurrentAnimalComplete(): boolean {
    const targetFruits = new Set(this.getCurrentTargetFruits());
    for (const fruit of targetFruits) {
      if (!this.collectedFruits.has(fruit)) {
        return false;
      }
    }
    return true;
  }

  completeCurrentAnimal(discardPile: FlipCard[]): void {
    this.collectedFruits.clear();
    this.currentAnimalIndex++;
  }

  reset(): void {
    this.currentAnimalIndex = 0;
    this.collectedFruits.clear();
    this.isActive = false;
  }
}